package managedBean;

import Merlion.MRP.bean.MaterialManagementBeanRemote;
import Merlion.SCM.bean.InventoryItemsBeanRemote;
import Merlion.SCM.entity.InventoryEntity;
import Merlion.util.state.InventoryState;
import Merlion.util.state.MRPRecordState;
import javax.faces.event.ActionEvent;
import java.util.Collection;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;

@ManagedBean(name = "MaterialRequirementManagedBean")
@ViewScoped
public class MaterialRequirementManagedBean {

    private MRPRecordState mrpList;
    private int requirementInCase;
    private int requirementInKgBatches;
    private int requirementInKg;
    private int scheduledReceipt;
    private int plannedReceipt;
    private int inHandInventory;
    private int plannedOrders;
    
    private Integer selectedYear;
    private Integer selectedMonth;
    private Long selectedMaterial;
    private String selectedMaterialName;
    private int selectedMaterialLeadtime;
    private int selectedMaterialBegInventory;
    private String lotSizeUnit;
    private Collection<InventoryState> materialList;
    
    @EJB
    private MaterialManagementBeanRemote MaterialManagementBean;
    @EJB
    private InventoryItemsBeanRemote InventoryItemsBean;
    
    public MaterialRequirementManagedBean() {
    }
    
    public void initView(PhaseEvent event) {
        System.out.println("**MaterialRequirementManagedBean: initView()");
        
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        if (materialList == null) {
            materialList = InventoryItemsBean.viewMaterials();
            materialList.size();
        }
    }
    
    public void doGenerateMRP(ActionEvent event) {
        try {
        System.out.println("**MaterialRequirementManagedBean: doGenerateMRP()");
        
        System.out.println(selectedYear);
        System.out.println(selectedMonth);
        System.out.println(selectedMaterial);
        mrpList = MaterialManagementBean.viewMRPRecord(selectedMaterial, selectedYear, selectedMonth);
        selectedMaterialName = mrpList.getMaterialName();
        selectedMaterialLeadtime = mrpList.getLeadtime();
        selectedMaterialBegInventory = mrpList.getBeginningInventory();
        lotSizeUnit = MaterialManagementBean.getLotSizeUnit(selectedMaterial);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public InventoryItemsBeanRemote getInventoryItemsBean() {
        return InventoryItemsBean;
    }

    public void setInventoryItemsBean(InventoryItemsBeanRemote InventoryItemsBean) {
        this.InventoryItemsBean = InventoryItemsBean;
    }

    public MaterialManagementBeanRemote getMaterialManagementBean() {
        return MaterialManagementBean;
    }

    public void setMaterialManagementBean(MaterialManagementBeanRemote MaterialManagementBean) {
        this.MaterialManagementBean = MaterialManagementBean;
    }

    public int getInHandInventory() {
        return inHandInventory;
    }

    public void setInHandInventory(int inHandInventory) {
        this.inHandInventory = inHandInventory;
    }

    public Collection<InventoryState> getMaterialList() {
        return materialList;
    }

    public void setMaterialList(Collection<InventoryState> materialList) {
        this.materialList = materialList;
    }

    public MRPRecordState getMrpList() {
        return mrpList;
    }

    public void setMrpList(MRPRecordState mrpList) {
        this.mrpList = mrpList;
    }

    public int getPlannedOrders() {
        return plannedOrders;
    }

    public void setPlannedOrders(int plannedOrders) {
        this.plannedOrders = plannedOrders;
    }

    public int getPlannedReceipt() {
        return plannedReceipt;
    }

    public void setPlannedReceipt(int plannedReceipt) {
        this.plannedReceipt = plannedReceipt;
    }

    public int getRequirementInCase() {
        return requirementInCase;
    }

    public void setRequirementInCase(int requirementInCase) {
        this.requirementInCase = requirementInCase;
    }

    public int getRequirementInKg() {
        return requirementInKg;
    }

    public void setRequirementInKg(int requirementInKg) {
        this.requirementInKg = requirementInKg;
    }

    public int getRequirementInKgBatches() {
        return requirementInKgBatches;
    }

    public void setRequirementInKgBatches(int requirementInKgBatches) {
        this.requirementInKgBatches = requirementInKgBatches;
    }

    public int getScheduledReceipt() {
        return scheduledReceipt;
    }

    public void setScheduledReceipt(int scheduledReceipt) {
        this.scheduledReceipt = scheduledReceipt;
    }

    public Long getSelectedMaterial() {
        return selectedMaterial;
    }

    public void setSelectedMaterial(Long selectedMaterial) {
        this.selectedMaterial = selectedMaterial;
    }

    public Integer getSelectedMonth() {
        return selectedMonth;
    }

    public void setSelectedMonth(Integer selectedMonth) {
        this.selectedMonth = selectedMonth;
    }

    public Integer getSelectedYear() {
        return selectedYear;
    }

    public void setSelectedYear(Integer selectedYear) {
        this.selectedYear = selectedYear;
    }

    public int getSelectedMaterialLeadtime() {
        return selectedMaterialLeadtime;
    }

    public void setSelectedMaterialLeadtime(int selectedMaterialLeadtime) {
        this.selectedMaterialLeadtime = selectedMaterialLeadtime;
    }

    public String getSelectedMaterialName() {
        return selectedMaterialName;
    }

    public void setSelectedMaterialName(String selectedMaterialName) {
        this.selectedMaterialName = selectedMaterialName;
    }

    public int getSelectedMaterialBegInventory() {
        return selectedMaterialBegInventory;
    }

    public void setSelectedMaterialBegInventory(int selectedMaterialBegInventory) {
        this.selectedMaterialBegInventory = selectedMaterialBegInventory;
    }

    public String getLotSizeUnit() {
        return lotSizeUnit;
    }

    public void setLotSizeUnit(String lotSizeUnit) {
        this.lotSizeUnit = lotSizeUnit;
    }
    
}
